import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

import java.util.concurrent.TimeUnit;
import java.util.Date;
import java.io.File;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.*;
import static org.openqa.selenium.OutputType.*;

public class bCreateCase {
    FirefoxDriver wd;
    
    @BeforeMethod
    public void setUp() throws Exception {
        wd = new FirefoxDriver();
        wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    }
    
    @Test
    public void bCreateCase() {
        wd.get("http://sd-gate.naumen.ru:10029/sd/");
        wd.findElement(By.id("username")).click();
        wd.findElement(By.id("username")).clear();
        wd.findElement(By.id("username")).sendKeys("tygrus");
        wd.findElement(By.id("password")).click();
        wd.findElement(By.id("password")).clear();
        wd.findElement(By.id("password")).sendKeys("1");
        wd.findElement(By.cssSelector("input.submit-button")).click();
        wd.findElement(By.xpath("//td[@id='gwt-debug-classesNavigationTree.classes:-image']/img")).click();
        wd.findElement(By.xpath("//td[@id='gwt-debug-NavigationTree.fqn:abstractBO-image']/img")).click();
        wd.findElement(By.id("gwt-debug-title-value")).click();
        wd.findElement(By.id("gwt-debug-title-value")).clear();
        wd.findElement(By.id("gwt-debug-title-value")).sendKeys("testCase");
        wd.findElement(By.id("gwt-debug-code-value")).click();
        wd.findElement(By.id("gwt-debug-code-value")).clear();
        wd.findElement(By.id("gwt-debug-code-value")).sendKeys("test");
        wd.findElement(By.cssSelector("div.g-button-text")).click();
    }
    
    @AfterMethod
    public void tearDown() {
        wd.quit();
    }
    
    public static boolean isAlertPresent(FirefoxDriver wd) {
        try {
            wd.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }
}
